<?php
/**
 * Created by PhpStorm.
 * User: ruma
 * Date: 2019/2/4
 * Time: 9:09
 */

namespace app\index\controller;


use app\common\controller\HomeBaseController;

class Index extends HomeBaseController
{
    public function index() {
        $headConf = ['title' => 'ZeBlog'];
        $this->assign('headConf', $headConf);
        //获取文章数据
        $articleData = db('article')->alias('a')
            ->join('__CATEGORY__ c', 'a.cate_id=c.cate_id')
            ->where('a.is_recycle', 2)
            ->order('sendtime desc')
            ->paginate(PAGINAGE_ARTICLE['webset_value'])
            ->each(function ($item, $key){
                $item['tags'] = db('arc_tag')->alias('at')
                    ->join('__TAG__ t', 'at.tid=t.tid')
                    ->where('at.arc_id', $item['arc_id'])
                    ->field('t.tid,t.tname')
                    ->select();
                return $item;
            });
//        halt($articleData);
//        foreach ($articleData as $k => $v) {
//            $articleData[$k]['tags'] = db('arc_tag')->alias('at')
//                ->join('__TAG__ t', 'at.tid=t.tid')
//                ->where('at.arc_id', $v['arc_id'])->field('t.tid,t.tname')->select();
//        }
        //halt($articleData);
        $page = $articleData->render();
        $this->assign('page',$page);
        $this->assign('articleData', $articleData);
        return $this->fetch();
    }

}